package com.idea.errorcode.api;

import com.idea.errorcode.messages.resolver.CachedMessageResolver;

/**
 * @author: 沉香
 * @date: 2025/04/13
 * @description: 异常断言工具类
 */
public final class ErrorAssert {


    public static <R extends RuntimeException> void isTrue(boolean condition,
                                                           TriFunction<String, String, Integer, R> exceptionFactory,
                                                           IErrorCode errorCode,
                                                           Object... args) {
        if (condition) {
            throw exceptionFactory.apply(errorCode.getErrorCode(), CachedMessageResolver.resolve(errorCode, args), errorCode.getCode());
        }
    }

    public static <R extends RuntimeException> void isFalse(boolean condition,
                                                           TriFunction<String, String, Integer, R> exceptionFactory,
                                                           IErrorCode errorCode,
                                                           Object... args) {
        if (!condition) {
            throw exceptionFactory.apply(errorCode.getErrorCode(), CachedMessageResolver.resolve(errorCode, args), errorCode.getCode());
        }
    }


}